package com.video.controller;

import com.qf.entity.Page;
import com.qf.entity.ResultData;
import com.qf.entity.RunLogEntity;
import com.video.service.IRunLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.List;

@Controller
@RequestMapping("/runlog")
public class RunLogController {

    @Autowired
    private IRunLogService runLogService;

    @Value("${page.size}")
    private Integer pageSize;

    /**
     * 搜索日志
     * @return
     */
    @RequestMapping("/search")
    @ResponseBody
    public ResultData<List<RunLogEntity>> search(String reqId) throws IOException {
        List<RunLogEntity> search = runLogService.search(reqId);
        return new ResultData<List<RunLogEntity>>().setCode(ResultData.ResultCodeList.OK).setData(search);
    }

    /**
     * 查询结果
     * @return
     */
    @RequestMapping("/searchlist")
    public String logList(Integer page, Model model) throws IOException {

        Page<List<RunLogEntity>> pages = new Page<List<RunLogEntity>>()
                .setPage(page == null ? 1 : page)
                .setPageSize(pageSize);

        Page<List<RunLogEntity>> resultPage = runLogService.searchList(pages);

        model.addAttribute("page", resultPage);

        return "loglist";
    }
}
